home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Dev / Sas-PPC / source / ppc__main.c
Encoding:
C/C++ Source or Header  |  1999-12-03  |  4.8 KB  |  177 lines

  1. #include <string.h>
  2. #include <exec/memory.h>
  3. #include <libraries/dosextens.h>
  4. #include <proto/dos.h>
  5. #include <proto/exec.h>
  6. #include <workbench/startup.h>
  7. #include <workbench/workbench.h>
  8. #include <workbench/icon.h>
  9. #include <proto/icon.h>
  10. #include <dos/dostags.h>
  11. #include <PowerUP/PPCLib/Interface.h>
  12. #include <PowerUP/PPCLib/tasks.h>
  13. #include <PowerUP/PPCLib/ppc.h>
  14. #include <PowerUP/PPCLib/object.h>
  15. #include <PowerUP/PPCDisslib/PPCDiss.h>
  16. #include <PowerUP/pragmas/ppc_pragmas.h>
  17. #include <PowerUP/clib/ppc_protos.h>
  18. #include <PowerUP/pragmas/ppcdiss_pragmas.h>
  19. #include <PowerUP/clib/ppcdiss_protos.h>
  20.  
  21. struct Library *PPCLibBase;
  22. char *_ProgramName;
  23. extern __near long _ElfEntry;
  24. extern __far int _PPCEntry(void);
  25. long _StackPtr;
  26. long __curdir;
  27. long __stack;
  28. long __base;
  29. long _ONEXIT;
  30. struct WBStartup *_WBenchMsg;
  31.  
  32. __stdargs int __fpinit(void)
  33. {
  34.     return 0;
  35. }
  36.  
  37. __stdargs void __fpterm(void)
  38. {
  39. }
  40.  
  41.  
  42. void __saveds __main(char *cmdline)
  43. {
  44.   void *MyObject;
  45.   long stacksize;
  46.   struct Process *parent_process;
  47.   struct CommandLineInterface *parent_cli;
  48.   char *rdargs_line;
  49.   int rdargs_length;
  50.   ULONG    Result = -1;
  51.   struct FileHandle *CurrentInput;
  52.   ULONG OldBuffer;
  53.   ULONG OldPosition;
  54.   ULONG OldEnd;
  55.   static struct TagItem    MyTags[14];
  56.   extern __far long _ElfObject;
  57.  
  58.  
  59.   parent_process = (void *)FindTask(NULL);
  60.   parent_cli =  (void *) ((long)(parent_process->pr_CLI) << 2);
  61.   stacksize = 0x10000;
  62.   if (parent_cli)
  63.       stacksize = parent_cli->cli_DefaultStack << 2;
  64.   if (stacksize < 0x10000) stacksize = 0x10000;
  65.  
  66.  
  67.   if ((PPCLibBase = OpenLibrary("ppc.library",0)) == NULL)
  68.      _XCEXIT(20);
  69.  
  70.  
  71.   rdargs_length = strlen(cmdline)+2;
  72.   rdargs_line = PPCAllocMem(rdargs_length, MEMF_ANY);
  73.   if (rdargs_line == NULL)
  74.   {
  75.       CloseLibrary((void *)PPCLibBase);
  76.       _XCEXIT(20);
  77.   }
  78.  
  79.   memcpy(rdargs_line, cmdline, rdargs_length-2);
  80.   rdargs_line[rdargs_length-2] = '\n';
  81.   rdargs_line[rdargs_length-1] = '\0';
  82.  
  83.   MyTags[0].ti_Tag = PPCELFLOADTAG_ELFADDRESS;
  84.   MyTags[0].ti_Data = (long)&_ElfObject;
  85.   MyTags[1].ti_Tag = PPCELFLOADTAG_ELFNAME;
  86.   MyTags[1].ti_Data = (long)_ProgramName;
  87.   MyTags[2].ti_Tag = TAG_DONE;
  88.  
  89.   CurrentInput        =(struct FileHandle*) BADDR(Input());
  90.   if (CurrentInput)
  91.   {
  92.      OldBuffer        =    CurrentInput->fh_Buf;
  93.      OldPosition        =    CurrentInput->fh_Pos;
  94.      OldEnd        =    CurrentInput->fh_End;
  95.   }
  96.   
  97.   if (MyObject=PPCLoadObjectTagList(MyTags))
  98.   {
  99.         static struct TagItem    MyTags[16];
  100.         struct PPCObjectInfo MyInfo;
  101.  
  102.         MyInfo.Address   =        0;
  103.         MyInfo.Name      =        "__Entry";
  104.         MyTags[0].ti_Tag =        TAG_END;
  105.  
  106.         PPCGetObjectAttrs(MyObject,
  107.                           &MyInfo,
  108.                           MyTags);
  109.         _ElfEntry = MyInfo.Address;
  110.  
  111.  
  112.         MyTags[0].ti_Tag    =    PPCTASKTAG_STOPTASK;
  113.         MyTags[0].ti_Data    =    FALSE;
  114.         MyTags[1].ti_Tag    =    PPCTASKTAG_WAITFINISH;
  115.         MyTags[1].ti_Data    =    TRUE;
  116.         MyTags[2].ti_Tag    =    PPCTASKTAG_INPUTHANDLE;
  117.         MyTags[2].ti_Data    =    (ULONG) Input();
  118.         MyTags[3].ti_Tag    =    PPCTASKTAG_OUTPUTHANDLE;
  119.         MyTags[3].ti_Data    =    (ULONG) Output();
  120.         MyTags[4].ti_Tag    =    PPCTASKTAG_ARG1;
  121.         MyTags[4].ti_Data    =    (ULONG) cmdline;
  122.         MyTags[5].ti_Tag    =    PPCTASKTAG_STACKSIZE;
  123.         MyTags[5].ti_Data    =    stacksize;
  124.         MyTags[6].ti_Tag    =    NP_CloseInput;
  125.         MyTags[6].ti_Data    =    FALSE;
  126.         MyTags[7].ti_Tag    =    NP_CloseOutput;
  127.         MyTags[7].ti_Data    =    FALSE;
  128.         MyTags[8].ti_Tag    =    PPCTASKTAG_BREAKSIGNAL;
  129.         MyTags[8].ti_Data    =    TRUE;
  130.         MyTags[9].ti_Tag    =    NP_Arguments;
  131.         MyTags[9].ti_Data    =    (ULONG)rdargs_line;
  132.         MyTags[10].ti_Tag       =       NP_Name;
  133.         MyTags[10].ti_Data      =       (ULONG)_ProgramName;
  134.         MyTags[11].ti_Tag       =       NP_CommandName;
  135.         MyTags[11].ti_Data      =       (ULONG)_ProgramName;
  136.         MyTags[12].ti_Tag    =    PPCTASKTAG_ARG3;
  137.         MyTags[12].ti_Data    =    (ULONG) __builtin_getreg(REG_A4);
  138.         MyTags[13].ti_Tag    =    PPCTASKTAG_ARG4;
  139.         MyTags[13].ti_Data    =    (ULONG) _PPCEntry;
  140.         MyTags[14].ti_Tag    =    PPCTASKTAG_ARG2;
  141.         MyTags[14].ti_Data    =    (ULONG) _WBenchMsg;
  142.  
  143.         MyTags[15].ti_Tag    =    TAG_END;
  144.  
  145.         Result=(ULONG) PPCCreateTask(MyObject,
  146.                                      &MyTags[0]);
  147.                                      
  148.  
  149.         if (CurrentInput)
  150.         {
  151.            UnGetC(Input(), -1);
  152.            CurrentInput->fh_Buf    =    OldBuffer;
  153.            CurrentInput->fh_Pos    =    OldPosition;
  154.            if (CurrentInput->fh_End)
  155.            {
  156.                CurrentInput->fh_End    =    OldEnd;
  157.            }
  158.         }
  159.         
  160.         PPCUnLoadObject(MyObject);
  161.   }
  162.   else
  163.   {
  164.     if (Output())
  165.     {
  166.         Write(Output(), "Can't load '", 12);
  167.         Write(Output(), _ProgramName, strlen(_ProgramName));
  168.         Write(Output(), "'\n", 2);
  169.     }
  170.   }
  171.   
  172.   PPCFreeMem(rdargs_line, rdargs_length);
  173.   CloseLibrary(PPCLibBase);
  174.   CloseLibrary((void *)DOSBase);
  175.   _XCEXIT((int)Result);
  176. }
  177.